﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KPIS.GERP.GHRMS.BLL;
using System.Data;
using System.Collections;
using KPIS.Utils;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IBLL;

namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class PS_NonWorkingJobSites : System.Web.UI.UserControl
    {
        private INonWorkingJobSiteBLL njsBLL = new NonWorkingJobSiteBLL();
        private IJobSiteBLL jsBLL = new JobSiteBLL();
        private RadComboBox cmbJobSite;
        private object _dataItem = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            cmbJobSite = (RadComboBox)cbJobSite.FindControl("cbJobSite");

            if (DataItem != null)
            {
                cbJobSite.ListJobSiteComboBox("2", "3");

                if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
                {
                    lblSeq.Text = DataBinder.Eval(DataItem, "Sequence").ToString();
                    cmbJobSite.SelectedValue = DataBinder.Eval(DataItem, "JobSite.Sequence").ToString();
                    txtRemarks.Text = DataBinder.Eval(DataItem, "Remarks").ToString();
                }
                else
                {

                }
                btnUpdate.Visible = !(DataItem is Telerik.Web.UI.GridInsertionObject);
                btnAddnew.Visible = (DataItem is Telerik.Web.UI.GridInsertionObject);
            }
        }

        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }
        protected void btnAddnew_Click(object sender, EventArgs e)
        {
            njsBLL.Insert(Int32.Parse(Session["NwdSequence"].ToString())
                , cmbJobSite.SelectedValue
                , txtRemarks.Text.Trim()
                , 1);

        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            njsBLL.Update(Int32.Parse(lblSeq.Text)
                , cmbJobSite.SelectedValue
                , txtRemarks.Text.Trim()
                , 1);
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }
    }
}